﻿<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">

<div data-options="region:'center',border:false" style="padding:2px;height: auto">
	<table id="role_list_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="
		   	 rownumbers:true,
		   	 pagination:true,
		   	 singleSelect:true,
		   	 toolbar : '#tb',
		   	 fitColumns : true,
		   	 url:'/role-list-json/1/10',
           method:'get',
           showFooter: true"
		>
		<thead>
		<tr>
			<th data-options="field:'roleName',width:90,align:'center'">角色名称</th>
			<th data-options="field:'rights',width:90,align:'center'" >权限码</th>
			<th data-options="field:'btnRights',width:90,align:'center'" >权限码</th>
        </tr>
		</thead>
	</table>
</div>


<div id="tb" style="padding:5px;height:auto">
	<#include "/common/button.html">
</div>

<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
        <div style="margin-bottom:10px">
            <input name="roleName" class="easyui-textbox" required="true" label="角色名称:" missingMessage="请输入角色名称" style="width:100%">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>

<script type="text/javascript">
	var url;
	//分配权限
	$("#assign").click(function(){
		var row = $('#role_list_table').datagrid('getSelected');
		if(!row){
		    layer.msg("请选择需要分配权限的角色",{icon: 2})
		}else{
			layer.open({
				type: 2,
				title: false,
				closeBtn: 0,
				shadeClose: true,
				area: ['757px', '300px'],
				skin: 'demo-class',
				content: '/admin-role-assign/'+row.rights+'/'+row.id
			});
		}
	})

	$('#assignButton').click(function(){
        var row = $('#role_list_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要分配权限的角色",{icon: 2})
        }else{
            layer.open({
                type: 2,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                area: ['757px', '300px'],
                skin: 'demo-class',
                content: '/admin-button-assign/'+row.rights+'/'+row.btnRights+'/'+row.id
            });
        }
	});

	//编辑
	$("#edit").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
		if (row){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
            $('#fm').form('load',row);
            url = '/role-ins-upd-del/'+row.id;
		} else {
            layer.msg("请选择需要编辑的角色",{icon: 2})
		}
	})

	//新增
	$("#add").click(function () {
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增角色');
        $('#fm').form('clear');
        url = '/role-ins-upd-del/-1';
	})

	//保存
    function saveUser(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
				$('#dlg').dialog('close');        // close the dialog
				$('#role_list_table').datagrid('reload');    // reload the user data
            }
        });
    }

	//删除
	$("#delete").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
		if(!row){
            layer.msg("请选择需要删除的角色",{icon: 2})
		}else{
            url = '/role-ins-upd-del/'+row.id;
            $.messager.confirm('删除信息','确定删除此角色?',function(r){
                if (r){
                    $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                        console.log('aaa');
						$('#role_list_table').datagrid('reload');    // reload the user data
                    });
                }
            });
		}
	})
</script>

